package com.ityj.yygh.hospital.controller.api;

import com.ityj.yygh.hospital.service.DepartmentService;
import com.ityj.yygh.hospital.service.HospitalSetService;
import com.ityj.yygh.hospital.service.HospitalService;
import com.ityj.yygh.hospital.service.ScheduleService;
import com.ityj.yygh.model.hosp.Hospital;
import com.ityj.yygh.model.hosp.Schedule;
import com.ityj.yygh.result.Result;
import com.ityj.yygh.vo.hosp.HospitalQueryVo;
import com.ityj.yygh.vo.hosp.ScheduleOrderVo;
import com.ityj.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api(value = "医院首页相关接口")
@RestController
@RequestMapping(path = "/api/hosp/hospital")
@Slf4j
public class HospitalApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    @Autowired
    private HospitalSetService hospitalSetService;

    @ApiOperation("查询医院列表")
    @GetMapping(path = "/findHospitalList/{page}/{limit}")
    public Result<Object> findHospitalList(@PathVariable("page") Integer page,
                                           @PathVariable("limit") Integer limit,
                                           HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> hospitals = hospitalService.searchHopitalInfoByCondition(hospitalQueryVo, page, limit);
        return Result.ok(hospitals);
    }

    @ApiOperation("根据医院名称模糊查询")
    @GetMapping(path = "/findByHositalNameLike/{hosname}")
    public Result<Object> findByHositalNameLike(@PathVariable("hosname") String hosname) {
        List<Hospital> hospitals = hospitalService.findByHositalNameLike(hosname);
        return Result.ok(hospitals);
    }

    @ApiOperation("根据医院编号获取医院预约挂号详情信息")
    @GetMapping(path = "/findItemDetail/{hoscode}")
    public Result<Map<String, Object>> findItemDetail(@PathVariable("hoscode") String hoscode) {
        Map<String, Object> result = hospitalService.findItemDetail(hoscode);
        return Result.ok(result);
    }

    @ApiOperation(value = "根据预约周期，展示可预约日期数据，按分页展示")
    @GetMapping("/auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result<Map<String, Object>> getBookingSchedule(@PathVariable("page") Integer page,
                                     @PathVariable("limit") Integer limit,
                                     @PathVariable("hoscode") String hoscode,
                                     @PathVariable("depcode") String depcode) {
        return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
    }

    @ApiOperation(value = "选择日期展示当天可预约列表")
    @GetMapping("/auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result<List<Schedule>> findScheduleList(@PathVariable("hoscode") String hoscode,
                                                   @PathVariable("depcode") String depcode,
                                                   @PathVariable("workDate") String workDate) {
        return Result.ok(scheduleService.findScheduleDetail(hoscode, depcode, workDate));
    }

    @ApiOperation(value = "根据排班ID获取排班信息")
    @GetMapping("/getSchedule/{scheduleId}")
    public Result<Schedule> findScheduleList(@PathVariable("scheduleId") String scheduleId) {
        return Result.ok(scheduleService.getScheduleById(scheduleId));
    }

    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("/inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @ApiParam(name = "scheduleId", value = "排班id", required = true)
            @PathVariable("scheduleId") String scheduleId) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    @ApiOperation(value = "获取医院签名信息")
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable("hoscode") String hoscode) {
        return hospitalSetService.getSignInfoVo(hoscode);
    }

}
